<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>Record and Play audio greetings in google wave</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta name="keywords" content="" />
<meta name="description" content="" />

<script type="text/javascript">
 
	var parentWin = window.parent;
	var listCount = 0;
	var thesource = "";
	var pingping;
	var addok = false;
	var dolist = false;
	var runPerd;
	var waitingForGoogle = true;
	var waveURL = "";
	
	window.onload = function () { 
		
//			runPerd = setInterval("waitingGoogle()", 200);

            window.addEventListener("message", function(e){ 
				if (e.origin.indexOf('googleusercontent.com') !== -1) {
					waitingForGoogle = false;
					var messages = e.data.split("~~om~~");
					switch (messages[0]){
					case "[ping]":
						waveURL = e.origin;
						parentWin.postMessage("[ping]~~om~~",waveURL);
						break;
					case "[getlist]":
						askPhp("getlist", messages);
						break;
					case "[addrec]":
						askPhp("addrec", messages);
						break;
					default:
					}
				}
			}, false);
		}

	function waitingGoogle() {
		if(!waitingForGoogle){
			clearInterval(runPerd);
		}else{
			parentWin.postMessage("[ping]~~om~~","https://0-wave-opensocial.googleusercontent.com");
		}
	}

	var reqPhp = function () {
		var ajaxReq;
		try{
			// Opera 8.0+, Firefox, Safari
			ajaxReq = new XMLHttpRequest();
		} catch (e){
			// Internet Explorer Browsers
			try{
				ajaxReq = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				try{
					ajaxReq = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e){
					return false;
				}
			}
		}
		ajaxReq.onreadystatechange = function () {
			if (ajaxReq.readyState == 4) {
				parentWin.postMessage(ajaxReq.responseText, waveURL);
			}
		}
		this.goget = function (e) {
			ajaxReq.open("GET", e, true);
			ajaxReq.send(null);	
		}
	}

	function askPhp(cmd, msg){
		var getmystuff = new reqPhp;
		getmystuff.goget("http://www.charlau.com/gwave/voicy/voicy.php?cmd=" + cmd + "&fl=" + msg[1] + "&pid=" + msg[2] + "&riffly_id=" + msg[3]);
	}

  </script>

</head>
<body>
</body>
</html>